#include "AppSettings.h"

#include "core/AppDirectory.h"
namespace {
const QString AppSettingsFilename = "app.settings.json";
}

AppSettings::AppSettings() {}

AppSettings& AppSettings::get()
{
    static AppSettings instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppFile(AppSettingsFilename)
        );
        instance.load();
    }
    return instance;
}

void AppSettings::fromJson(const QJsonObject& json, QStringList& errorList)
{

    appDocDir_ = json["appDocDir"].toString(appDocDir_);
}

QJsonObject AppSettings::toJson() const
{
    QJsonObject json = BaseDocument::toJson();

    json.insert("appDocDir", QJsonValue(this->appDocDir_));

    postToJosn();
    return json;
}

void AppSettings::postToJosn() const
{
    AppDirectory::get().setDocDir(this->appDocDir_);
}
